package com.rain.service.impl;

import com.rain.enums.PageSize;
import com.rain.query.SimplePage;
import com.rain.entity.EtLine;
import com.rain.query.EtLineQuery;
import com.rain.query.PaginationResult;
import com.rain.mapper.EtLineMapper;
import com.rain.service.EtLineService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
/**
 * @auther: rain
 * @description: （Electric Transmission Line）输电线路Service
 * @date: 2025-10-31
 */

@Service("etLineService")
public class EtLineServiceImpl implements EtLineService{

	@Resource
	private EtLineMapper<EtLine, EtLineQuery> etLineMapper;

	/**
	 * 根据条件查询列表
	 */
	public List<EtLine> findListByParam(EtLineQuery query) {

		return this.etLineMapper.selectList(query);

	}

	/**
	 * 根据条件查询数量
	 */
	public Long findCountByParam(EtLineQuery query) {

		return this.etLineMapper.selectCount(query);

	}

	/**
	 * 分页查询
	 */
	public PaginationResult<EtLine> findListByPage(EtLineQuery query) {

		Long count = etLineMapper.selectCount(query);
		Integer pageNo = query.getPageNo() == null ? 1 : query.getPageNo();
		Integer pageSize = query.getPageSize() == null ? PageSize.SIZE15.getSize() : query.getPageSize();
		SimplePage simplePage = new SimplePage(query.getPageNo(), query.getPageSize(), count);
		query.setSimplePage(simplePage);
		List<EtLine> list = etLineMapper.selectList(query);
		PaginationResult<EtLine> result = new PaginationResult(count, simplePage.getPageNo(), simplePage.getPageSize(), simplePage.getPageTotal(),list);
		return result;

	}

	/**
	 * 新增
	 */
	public Integer add(EtLine bean) {

		return etLineMapper.insert(bean);

	}

	/**
	 * 批量新增
	 */
	public Integer addBatch(List<EtLine> listBean) {

		if(listBean == null || listBean.isEmpty()) {
		return 0;
		}
		return etLineMapper.insertBatch(listBean);

	}

	/**
	 * 批量新增修改
	 */
	public Integer addOrUpdateBatch(List<EtLine> listBean) {

		if(listBean == null || listBean.isEmpty()) {
		return 0;
		}
		return etLineMapper.insertOrUpdateBatch(listBean);

	}

	/**
	 * 根据Id查询
	 */
	public EtLine getEtLineById(Integer id) {

		return etLineMapper.selectById(id);

	}

	/**
	 * 根据Id更新
	 */
	public Integer updateEtLineById(EtLine bean, Integer id){

		return etLineMapper.updateById(bean, id);

	}

	/**
	 * 根据Id删除
	 */
	public Integer deleteEtLineById(Integer id) {

		return etLineMapper.deleteById(id);

	}

}